package com.gaussian.property.module.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gaussian.property.module.biz.entity.DailyStatistics;
import com.gaussian.property.module.biz.mapper.DailyStatisticsMapper;
import com.gaussian.property.module.biz.service.IDailyStatisticsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

import static cn.hutool.core.date.DatePattern.PURE_DATE_FORMATTER;

/**
 * <p>
 * ics项目维度指标每日汇总 服务实现类
 * </p>
 *
 * @author songqi(13776346982)
 * @since 2024-10-03
 */
@Service
public class DailyStatisticsServiceImpl extends ServiceImpl<DailyStatisticsMapper, DailyStatistics> implements IDailyStatisticsService {


    @Override
    public List<DailyStatistics> getDailyStatisticsList(String projectId, LocalDate startDate, LocalDate endDate) {
        QueryWrapper<DailyStatistics> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .ge(DailyStatistics::getStatisticsDate, startDate.format(PURE_DATE_FORMATTER))
                .le(DailyStatistics::getStatisticsDate, endDate.format(PURE_DATE_FORMATTER))
                .eq(DailyStatistics::getItemId, projectId);
        queryWrapper.orderByAsc("STR_TO_DATE('statistics_date', '%Y%m%d')");
        return super.list(queryWrapper);
    }

}
